package com.rcpcompany.ui.flows;

import com.rcpcompany.utils.logging.LogUtils;

/**
 * Abstract base class for {@link IFlowDirector flow directors} with just one
 * page.
 * 
 * @author Tonny Madsen, The RCP Company
 */
public class OnePageFlowDirector extends AbstractFlowDirector {

	/**
	 * The singleton flow page of the director
	 */
	final private IFlowPage myPage;

	/**
	 * Constructs and returns a new director for the single page...
	 * 
	 * @param title
	 *            the title of the director
	 * @param page
	 *            the single page of the director
	 */
	public OnePageFlowDirector(String title, IFlowPage page) {
		super(title);
		myPage = page;
	}

	@Override
	public boolean isNavigationButtonWanted(WhereTo where) {
		switch (where) {
		case NEXT_STEP:
			return true;
		default:
			return false;
		}
	}

	public boolean canNavigate(WhereTo where) {
		switch (where) {
		case NEXT_STEP:
			return true;
		default:
			return false;
		}
	}

	public IFlowPage getCurrentPage() {
		return myPage;
	}

	public void navigate(WhereTo where) {
		LogUtils.debug(this, "Navigate " + where); //$NON-NLS-1$
		switch (where) {
		case FIRST:
		case PREVIOUS_STEP:
			return;
		case FINISH:
		case NEXT_STEP:
		case CANCEL:
			getContainer().closeDirector(this);
			return;
		}
	}
}
